//
//  SHStatusToolBarView.swift
//  SHWeibo01
//
//  Created by 卫平玉 on 16/7/23.
//  Copyright © 2016年 卫平玉. All rights reserved.
//

import UIKit




class SHStatusToolBarView: UIView {
    
    var retweetButton: UIButton?
    
    var commentButton: UIButton?
    
    var unlikeButton: UIButton?
    
    //定义一个属性供外界赋值
    var statusViewModel: SHStatusViewModel?{
        
        didSet{
            
            retweetButton?.setTitle(statusViewModel?.repostsCountStr, forState: UIControlState.Normal)
            
            commentButton?.setTitle(statusViewModel?.commentsCountStr, forState: UIControlState.Normal)
            unlikeButton?.setTitle(statusViewModel?.attitudesCountStr, forState: UIControlState.Normal)
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setupUI()
    }

    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func setupUI(){
        

        
         retweetButton = addChildButton("timeline_icon_retweet", title: "转发")
        
         commentButton = addChildButton("timeline_icon_comment", title: "评论")
        
         unlikeButton = addChildButton("timeline_icon_unlike", title: "赞")
        
        let line1 = addChildLine()
        
        let line2 = addChildLine()
        
        retweetButton!.snp_makeConstraints { (make) -> Void in
            make.top.bottom.leading.equalTo(self)
            
            make.width.equalTo(commentButton!)
            
        }
        
        commentButton!.snp_makeConstraints { (make) -> Void in
            make.top.bottom.equalTo(self)
            make.leading.equalTo(retweetButton!.snp_trailing)
            make.width.equalTo(unlikeButton!)
        }
        
        unlikeButton!.snp_makeConstraints { (make) -> Void in
            make.top.bottom.trailing.equalTo(self)
            
            make.leading.equalTo(commentButton!.snp_trailing)
            make.width.equalTo(retweetButton!)
        }
        
        line1.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(self)
            make.centerX.equalTo(retweetButton!.snp_trailing)
        }
        
        line2.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(self)
            
            make.centerX.equalTo(commentButton!.snp_trailing)
        }
    }
    
    func addChildLine()->UIImageView{
        
        let img = UIImageView(imgName: "timeline_card_bottom_line")
        addSubview(img)
        
        return img
    }
    
    func addChildButton(imgName: String,title: String) -> UIButton{
        
        let button = UIButton()
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        button.setTitle(title, forState: UIControlState.Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: UIControlState.Normal)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        
        button.setImage(UIImage(named: imgName), forState: UIControlState.Normal)
        
        addSubview(button)
        
        return button
    }
}
